import assert = require("assert");
import { AuthService } from './../src/service/authService';
import { MPJRequestManager, MPJRequestMock } from "../src/common/http/mpjRequest";
const webconfig = require("../webconfig").webconfig;

describe("AuthService Test", () => {
    let authService = new AuthService();
    let storeId: string = webconfig.storeId;
    describe("login", () => {
        it("密码错误", async () => {
            let mpjRequestMock = new MPJRequestMock();
            let res = {
                result: "FAILED",
                code: "USER_PASSWD_ERR"
            };
            mpjRequestMock.MockData('/api/stores/' + storeId + '/employees/v2/login', res);
            MPJRequestManager.Current.RegistMPJRequest(mpjRequestMock);
            try {
                await authService.login(storeId, "18583920602", "e10adc3949ba59abbe56e057f20f883e");
                assert.fail();
            }
            catch (e) {
                assert.equal(e.Message, "用户名或密码错误！");
            }
        });
        it("员工不存在该店铺", async () => {
            let mpjRequestMock = new MPJRequestMock();
            let res = {
                result: "FAILED",
                code: "NOT_BELONG_TO_SHOP"
            };
            mpjRequestMock.MockData('/api/stores/' + storeId + '/employees/v2/login', res);
            MPJRequestManager.Current.RegistMPJRequest(mpjRequestMock);
            try {
                await authService.login(storeId, "18583920602", "e10adc3949ba59abbe56e057f20f883e");
                assert.fail();
            }
            catch (e) {
                assert.equal(e.Message, "该店员不属于本店铺！");
            }
        });
        //it("店铺已过期");
        it("角色不存在");
        it("角色为空");
        it("没有权限");
    });
})